#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   Bootloader_ControlDTCSetting_0x85_test.py
@Time    :   2022/08/29 13:31:28
@Author  :   YangLiang 
@Version :   1.0
@Contact :   yangliang@chengtech.com
@License :   (C)Copyright 2022-2025
@Desc    :   None
'''

# here put the import lib
from pytest_assume.plugin import assume
 
import pytest
import time
import requests
from sympy import I
# from sympy import assuming
from commDriver.TS_CAN import *
import allure
import sys
from collections.abc import Iterable

from sqlalchemy import false
sys.dont_write_bytecode = True

controlDTCSetting = [([0x85, 0x01], [0xC5, 0X01]),
                     ([0x85, 0x02], [0xC5, 0X02])
                     ]

controlDTCSetting_NRC13_Phy = [
                                 ([0x85],[0x7F, 0X85, 0x13]),           
                                 ([0x85,0x02,0x01],[0x7F, 0X85, 0x13]), 
                                 ([0x85,0x01,0xFF],[0x7F, 0X85, 0x13]), 
                                 ([0x85,0x22,0x13],[0x7F, 0X85, 0x13])
                              ]

controlDTCSetting_NRC12_Phy = [ 
                                 ([0x85,0x00],[0x7F, 0X85, 0x12]), 
                                 ([0x85,0x03],[0x7F, 0X85, 0x12]),
                                 ([0x85,0x3F],[0x7F, 0X85, 0x12]),        
                                 ([0x85,0x40],[0x7F, 0X85, 0x12]), 
                                 ([0x85,0x5F],[0x7F, 0X85, 0x12]),          
                                 ([0x85,0x60],[0x7F, 0X85, 0x12]), 
                                 ([0x85,0x7E],[0x7F, 0X85, 0x12]),          
                                 ([0x85,0x7F],[0x7F, 0X85, 0x12]) 
                              ]

controlDTCSettingSuppressPosMsgBit = [  ([0x85, 0x81], []),
                                        ([0x85, 0x82], [])
                                   ]

controlDTCSetting_SuppressPosMsgBit_NRC13 = [     ([0x85,0x82,0x01], [0x7F,0x85,0x13]),
                                                  ([0x85,0x81,0xFF], [0x7F,0x85,0x13]),
                                                  ([0x85,0x82,0x13], [0x7F,0x85,0x13]) 
                                             ]

controlDTCSetting_SuppressPosMsgBit_NRC12 = [     ([0x85,0x80],[0x7F, 0X85, 0x12]),
                                                  ([0x85,0x83],[0x7F, 0X85, 0x12]),
                                                  ([0x85,0x8F],[0x7F, 0X85, 0x12]),         
                                                  ([0x85,0x40],[0x7F, 0X85, 0x12]),
                                                  ([0x85,0x5F],[0x7F, 0X85, 0x12]),        
                                                  ([0x85,0x60],[0x7F, 0X85, 0x12]),
                                                  ([0x85,0x7E],[0x7F, 0X85, 0x12]),         
                                                  ([0x85,0x7F],[0x7F, 0X85, 0x12])
                                             ]


class Test_ControlDTCSetting_Phy(object):
     ids = ['{0}'.format(binascii.b2a_hex(bytearray(req), ' ')) for req, resp in controlDTCSetting]
     @allure.severity('normal')
     @allure.story('Control DTC Setting Test')
     @allure.title('Test positive response of control dtc setting 0x85')
     @allure.description('Test positive response of 0x85')
     @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
     @pytest.mark.parametrize('req,resp', controlDTCSetting, ids=ids)
     def test_ControlDTCSetting_Programming_Phy(self,action,Driver, req, resp):
          iStep = 1
          iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)


     ids = ['{0}'.format(binascii.b2a_hex(bytearray(req), ' ')) for req, resp in controlDTCSetting_NRC13_Phy]
     @allure.severity('minor')         
     @allure.title('Test negative response of control dtc setting 0x85')
     @allure.description('Test negative response code of 0x28 when suppressPosMsgBit is extended with physical addressing')
     @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
     @pytest.mark.parametrize('req,resp', controlDTCSetting_NRC13_Phy, ids=ids)
     def test_ControlDTCSetting_NRC13_Phy(self,action,Driver,req, resp):
          iStep = 1
          iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)


     ids = ['{0}'.format(binascii.b2a_hex(bytearray(req), ' ')) for req, resp in controlDTCSetting_NRC12_Phy]
     @allure.severity('minor')         
     @allure.title('Test negative response of control dtc setting 0x85')
     @allure.description('Test negative response code of 0x28 when suppressPosMsgBit is extended with physical addressing')
     @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
     @pytest.mark.parametrize('req,resp', controlDTCSetting_NRC12_Phy, ids=ids)
     def test_ControlDTCSetting_NRC12_Phy(self,action,Driver,req, resp):
          iStep = 1
          iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)


         
     ids = ['{0}'.format(binascii.b2a_hex(bytearray(req), ' ')) for req, resp in controlDTCSettingSuppressPosMsgBit]
     @allure.severity('normal') 
     @allure.title('Test positive response of control dtc setting 0x85 when suppressPosMsgBit is enabled')
     @allure.description('Test positive response of 0x85  when suppressPosMsgBit is enabled with physical addressing')
     @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
     @pytest.mark.parametrize('req,resp', controlDTCSettingSuppressPosMsgBit, ids=ids)
     def test_ControlDTCSetting_SuppressPosMsgBit_programming_Phy(self,action,Driver,req, resp):
          iStep = 1
          iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)

     ids = ['{0}'.format(binascii.b2a_hex(bytearray(req), ' ')) for req, resp in controlDTCSetting_SuppressPosMsgBit_NRC13]
     @allure.severity('minor')         
     @allure.title('Test negative response of control dtc setting 0x85 when suppressPosMsgBit is enabled')
     @allure.description('Test negative response code of 0x85 when suppressPosMsgBit is enabled with physical addressing')
     @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
     @pytest.mark.parametrize('req,resp', controlDTCSetting_SuppressPosMsgBit_NRC13, ids=ids)
     def test_ControlDTCSetting_SuppressPosMsgBit_NRC13_Phy(self,action,Driver,req, resp):
          iStep = 1
          iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)

     ids = ['{0}'.format(binascii.b2a_hex(bytearray(req), ' ')) for req, resp in controlDTCSetting_SuppressPosMsgBit_NRC12]
     @allure.severity('minor')         
     @allure.title('Test negative response of control dtc setting 0x85 when suppressPosMsgBit is enabled')
     @allure.description('Test negative response code of 0x85 when suppressPosMsgBit is enabled with physical addressing')
     @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
     @pytest.mark.parametrize('req,resp', controlDTCSetting_SuppressPosMsgBit_NRC12, ids=ids)
     def test_ControlDTCSetting_SuppressPosMsgBit_NRC12_Phy(self,action,Driver,req, resp):
          iStep = 1
          iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)
         